package com.biz.primus.account.service;

import com.biz.primus.account.config.CasConfig;
import com.biz.primus.account.feign.AuthorityFeignClient;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenusRegisterReqVO;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by defei on 11/21/17.
 */
@Service
@Slf4j
public class AuthInitializeService {

    private final AuthorityFeignClient authorityFeignClient;

    private final CasConfig casConfig;

    @Autowired
    public AuthInitializeService(AuthorityFeignClient authorityFeignClient, CasConfig casConfig) {
        this.authorityFeignClient = authorityFeignClient;
        this.casConfig = casConfig;
    }

    public void registerMenu(List<MenuGroupVO> menuGroups) {

        MenusRegisterReqVO reqVO = new MenusRegisterReqVO();
        reqVO.setApplicationType(casConfig.getApplicationType());
        reqVO.setMenuGroups(menuGroups);
        try {
            authorityFeignClient.authorityRegister(reqVO);
        } catch (Throwable e) {
            log.warn("Initialize menus failed... !!!!!!!!");
        }
    }
}
